cmake_minimum_required(VERSION 3.18.0)
cmake_policy(SET CMP0011 NEW)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99")
# 设置构建类型为Debug
set(CMAKE_BUILD_TYPE Debug)

# 包含库目录
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/lib)

add_executable(Server src/Server.c
        src/controller/BucketsController.c src/service/BucketsService.c src/mapper/BucketsMapper.c src/utils/BucketsUtils.c src/cache/BucketCache.c src/local/buckets/BucketsMeta.c src/utils/BucketsAccess.c
        src/common/SDS.c src/common/HashTable.c src/common/LinkedList.c src/common/YXConfig.c src/common/YXLog.c src/common/YXNet.c
        src/common/YXTime.c src/common/YXThreadPool.c src/Route.c src/common/cJSON.c src/common/YXMalloc.c src/common/YXBase64.c
        src/common/YXJwt.c src/ServerStruct.h src/Console.c src/common/YXFile.c
        src/common/YXIO.c src/HttpClient.c src/HttpResponse.c src/HttpRequest.c
        src/HttpFixedResponse.c src/common/YXLRU.c
        src/common/YXMySQL.c
        src/common/YXJSON.c
        src/common/YXResult.c
        src/common/YXString.c
        src/controller/AuthController.c src/service/AuthService.c src/mapper/AuthMapper.c
        src/DataSourceInstance.c
        src/common/Trie.c
        src/controller/ObjectsController.c
        src/service/ObjectsService.c
        src/mapper/ObjectsMapper.c
)

add_executable(YXJwtTest test/YXJwtTest.c
        src/common/YXJwt.c src/common/YXBase64.c src/common/YXLog.c
        src/common/YXConfig.c src/common/SDS.c src/common/HashTable.c
)

add_executable(SDSTest test/SDSTest.c src/common/SDS.c)
add_executable(LinkedListTest test/LinkedListTest.c src/common/LinkedList.c)
add_executable(YXLRUTest test/YXLRUTest.c src/common/YXLRU.c src/common/HashTable.c src/common/YXLog.c src/common/YXConfig.c src/common/SDS.c)
add_executable(MySQLTest test/MySQLTest.c
        src/common/YXMySQL.c
        src/common/YXLog.c src/common/LinkedList.c
        src/common/YXConfig.c src/common/SDS.c src/common/HashTable.c
        src/common/cJSON.c
        src/common/YXJSON.c
        src/common/YXResult.c
)

# 链接库
if (UNIX)
    set(jwt "l8w8jwt")
elseif (WIN32)
    set(jwt "l8w8jwt2")
    target_link_libraries(Server ws2_32)
endif ()

target_link_libraries(Server ${jwt} mysql)
target_link_libraries(YXJwtTest ${jwt})
target_link_libraries(MySQLTest mysql)

# 设置可执行文件的输出路径
set_target_properties(Server PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")

# 设置目标属性，将配置文件拷贝到可执行文件所在的目录
set(INPUT_DIR "${PROJECT_SOURCE_DIR}")
set(OUTPUT_DIR "${CMAKE_BINARY_DIR}")

# 拷贝项目相关资源文件
file(COPY ${INPUT_DIR}/lib/ DESTINATION ${OUTPUT_DIR}/bin)
file(COPY ${INPUT_DIR}/static/ DESTINATION ${OUTPUT_DIR}/static)
file(COPY ${INPUT_DIR}/conf/ DESTINATION ${OUTPUT_DIR}/conf)
add_executable(Test test/Test.c)